package com.dsz.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name="t_roles")
@GenericGenerator(name="sys-uuid",strategy="uuid")
public class Roles {
	@Id
	@GeneratedValue(generator="sys-uuid")
	private String rid;
	private String rname;
	/**
	 * 与用户表多对多
	 */
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="t_users_roles",//维护与中间表的关系
	joinColumns= {@JoinColumn(name="rid")},
	inverseJoinColumns= {@JoinColumn(name="sid")})
	//在json解析时，只忽略users实体类中的rs属性
	@JsonIgnoreProperties("rs")
	//当属性是实体类对象时，可以使用@JsonIgnoreProperties来忽略
	private List<Users> us;
	
	/**
	 * 与模块表多对多
	 */
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="t_roles_modules",
	joinColumns = @JoinColumn(name="rid"),
	inverseJoinColumns = @JoinColumn(name="mid")
			)
	private List<Modules> ms;

	public Roles(String rid, String rname) {
		this.rid = rid;
		this.rname = rname;
	}

	public Roles() {
	}

	public String getRid() {
		return rid;
	}

	public void setRid(String rid) {
		this.rid = rid;
	}

	public String getRname() {
		return rname;
	}

	public void setRname(String rname) {
		this.rname = rname;
	}

	public List<Users> getUs() {
		return us;
	}

	public void setUs(List<Users> us) {
		this.us = us;
	}

	public List<Modules> getMs() {
		return ms;
	}

	public void setMs(List<Modules> ms) {
		this.ms = ms;
	}

	@Override
	public String toString() {
		return "Roles [rid=" + rid + ", rname=" + rname + ", us=" + us + ", ms=" + ms + "]";
	}


	
	
	
}



















